//
//  UIBUtton+Extension.swift
//  GLWeiBo
//
//  Created by mac on 16/5/10.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

extension UIButton {
    convenience init(
        title: String?,
        titleColor: UIColor,
        fontSize: CGFloat,
        imageName: String? = nil,
        backgroundImageName: String? = nil) {
            self.init()
            if let title = title {
                setTitle(title, forState: UIControlState.Normal)
            }
            titleLabel?.font = UIFont.systemFontOfSize(fontSize)
            setTitleColor(titleColor, forState: UIControlState.Normal)
            if let imageName = imageName {
                setImage(UIImage(named: imageName), forState: .Normal)
                setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)

            }
            if let backgroundImageName = backgroundImageName {
                setBackgroundImage(UIImage(named: backgroundImageName), forState: .Normal)
                setBackgroundImage(UIImage(named: backgroundImageName + "_highlighted"), forState: .Highlighted)
        }
        sizeToFit()
    }
}